﻿//-----------------------------------------------------------------------
// <copyright file="EditWorkerViewModel.cs" company="FER">
//     Copyright (c) All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace NMBP.ViewModels
{
    using System;
    using System.Collections.Generic;
    using GalaSoft.MvvmLight;
    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight.Messaging;
    using NMBP.DAL;
    using NMBP.Models;
    using NMBP.ViewModels.Dialogs;

    /// <summary>
    /// This class contains properties that the customer View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class EditWorkerViewModel : ViewModelBase
    {
        #region Binding Fields
        /// <summary>
        /// Gets or sets worker name
        /// </summary>
        private string name;

        /// <summary>
        /// Gets or sets worker surname
        /// </summary>
        private string surname;

        /// <summary>
        /// Gets or sets worker username
        /// </summary>
        private string username;

        /// <summary>
        /// Gets or sets worker password
        /// </summary>
        private string password;

        /// <summary>
        /// Gets or sets worker contact
        /// </summary>
        private string contact;

        /// <summary>
        /// Gets or sets worker sallary
        /// </summary>
        private float sallary;

        /// <summary>
        /// Gets or sets worker VpnNumber
        /// </summary>
        private string vpnNumber;

        /// <summary>
        /// Gets or sets worker department
        /// </summary>
        private Department department;

        /// <summary>
        /// Gets or sets the list of available departments
        /// </summary>
        private List<Department> availableDepartments;

        /// <summary>
        /// Gets or sets whether the worker is a manager or not
        /// </summary>
        private bool isManager;

        /// <summary>
        /// Gets or sets whether the worker has admin rights or not
        /// </summary>
        private bool isAdmin;

        /// <summary>
        /// Action raised when worker view model needs to be initialized
        /// </summary>
        private Action<Worker> initWorkerViewModel;
        #endregion

        /// <summary>
        /// Gets or sets the received worker
        /// </summary>
        private Worker recievedWorker;

        /// <summary>
        /// Initializes a new instance of the EditWorkerViewModel class
        /// </summary>
        public EditWorkerViewModel()
        {
            this.initWorkerViewModel = new Action<Worker>(this.InitializeViewModel);
            Messenger.Default.Register<Worker>(this, "InitializeEditWorker", this.initWorkerViewModel);

            this.SaveEditWorker = new RelayCommand(
                () =>
                {
                    this.recievedWorker.Name = this.Name;
                    this.recievedWorker.Surname = this.Surname;
                    this.recievedWorker.Username = this.Username;
                    this.recievedWorker.Password = this.Password;
                    this.recievedWorker.Contact = this.Contact;

                    // TODO:... nastaviti
                });
        }

        #region Bindable Properties
        /// <summary>
        /// Gets or sets dbFacade
        /// </summary>
        public IDbFacade DbFacade { get; set; }

        /// <summary>
        /// Gets or sets dialog service
        /// </summary>
        public IDialogService DialogService { get; set; }

        /// <summary>
        /// Gets or sets worker name
        /// </summary>
        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.name = value;
                this.RaisePropertyChanged("Name");
            }
        }

        /// <summary>
        /// Gets or sets worker surname
        /// </summary>
        public string Surname
        {
            get
            {
                return this.surname;
            }

            set
            {
                this.surname = value;
                this.RaisePropertyChanged("Surname");
            }
        }

        /// <summary>
        /// Gets or sets worker username
        /// </summary>
        public string Username
        {
            get
            {
                return this.username;
            }

            set
            {
                this.username = value;
                this.RaisePropertyChanged("Username");
            }
        }

        /// <summary>
        /// Gets or sets worker password
        /// </summary>
        public string Password
        {
            get
            {
                return this.password;
            }

            set
            {
                this.password = value;
                this.RaisePropertyChanged("Password");
            }
        }

        /// <summary>
        /// Gets or sets worker contact
        /// </summary>
        public string Contact
        {
            get
            {
                return this.contact;
            }

            set
            {
                this.contact = value;
                this.RaisePropertyChanged("Contact");
            }
        }
        #endregion

        #region Bindable commands
        /// <summary>
        /// Gets the command raised when save edit worker button is clicked
        /// </summary>
        public RelayCommand SaveEditWorker { get; private set; }

        /// <summary>
        /// Gets the command raised when cancel edit worker button is clicked
        /// </summary>
        public RelayCommand CancelEditWorker { get; private set; }
        #endregion

        /// <summary>
        /// Initializes view model
        /// </summary>
        /// <param name="worker">Worker to initialize view model</param>
        private void InitializeViewModel(Worker worker)
        {
            if (this.DbFacade == null)
            {
                this.DbFacade = new DbFacade();
            }
        }
    }
}
